import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    meta: { roles: ['admin', 'editor'] },
    children: [
      {
        path: 'dashboard',
        // component: () => import('@/views/dashboard/index'),
        component: () => import('@/views/VisualizationOfDetectionResults/realTimeVideo.vue'),
        name: '主界面',
        meta: { title: '实时检测', icon: 'el-icon-video-camera', affix: true }
      }
    ]
  }

]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // 注释掉实时预览，把主界面改为实时预览
  // {
  //   path: '/visualization',
  //   component: Layout,
  //   redirect: 'noRedirect',
  //   name: 'visualization',
  //   meta: {
  //     title: '实时检测',
  //     icon: 'chart'
  //   },
  //   children: [
  //     {
  //       path: '实时检测',
  //       component: () => import('@/views/VisualizationOfDetectionResults/test2'),
  //       name: '实时检测',
  //       meta: { title: '实时检测', noCache: true }
  //     }
  //   ]
  // },
  // {
  //   path: '/permission',
  //   component: Layout,
  //   redirect: '/permission/page',
  //   alwaysShow: true, // will always show the root menu
  //   name: 'Permission',
  //   meta: {
  //     title: 'Permission',
  //     icon: 'lock',
  //     roles: ['admin', 'editor'] // you can set roles in root nav
  //   },
  //   children: [
  //     {
  //       path: 'page',
  //       component: () => import('@/views/permission/page'),
  //       name: 'PagePermission',
  //       meta: {
  //         title: 'Page Permission',
  //         roles: ['admin'] // or you can only set roles in sub nav
  //       }
  //     },
  //     {
  //       path: 'directive',
  //       component: () => import('@/views/permission/directive'),
  //       name: 'DirectivePermission',
  //       meta: {
  //         title: 'Directive Permission'
  //         // if do not set roles, means: this page does not require permission
  //       }
  //     },
  //     {
  //       path: 'role',
  //       component: () => import('@/views/permission/role'),
  //       name: 'RolePermission',
  //       meta: {
  //         title: 'Role Permission',
  //         roles: ['admin']
  //       }
  //     }
  //   ]
  // },
  /*
    用户设置模块，里面有分为三个子模块。
    1、用户管理模块，管理员能够对用户进行增删改查操作。
    2、全局设置模块，管理员能够对算法的一些违禁品，危险品等的设置。
  */
  {
    path: '/userset',
    component: Layout,
    redirect: '/userset/control',
    name: 'userset',
    meta: {
      title: '用户设置',
      icon: 'el-icon-user-solid',
      roles: ['admin']
    },
    children: [
      {
        path: 'control',
        component: () => import('@/views/userset/control'),
        name: 'user_control',
        meta: { title: '用户管理' }
      }
      // {
      //   path: 'param',
      //   component: () => import('@/views/userset/param'),
      //   name: 'paramset',
      //   meta: { title: '违禁品设置' }
      // }
    ]
  },

  /** when your routing map is too long, you can split it into small modules **/

  // chartsRouter,

  // {
  //   path: '/error',
  //   component: Layout,
  //   redirect: 'noRedirect',
  //   name: 'ErrorPages',
  //   meta: {
  //     title: 'Error Pages',
  //     icon: '404'
  //   },
  //   children: [
  //     {
  //       path: '401',
  //       component: () => import('@/views/error-page/401'),
  //       name: 'Page401',
  //       meta: { title: '401', noCache: true }
  //     },
  //     {
  //       path: '404',
  //       component: () => import('@/views/error-page/404'),
  //       name: 'Page404',
  //       meta: { title: '404', noCache: true }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true },
  {
    path: '/category',
    component: Layout,
    redirect: '/noRedirect',
    meta: {
      title: '数据查询和统计',
      icon: 'el-icon-data-analysis',
      roles: ['admin']
    },
    children: [
      {
        path: 'category',
        component: () => import('@/views/CategorySettings/index'),
        name: 'Category',
        meta: { title: '违禁品识别设置', noCache: true }
      }
    ]
  },
  {
    path: '/dataQueryAndStatistics',
    component: Layout,
    redirect: 'noRedirect',
    name: '数据查询和统计',
    meta: {
      title: '数据查询和统计',
      icon: 'el-icon-data-analysis',
      roles: ['admin', 'editor']
    },
    children: [
      {
        path: '/dataQuery',
        component: () => import('@/views/DataQueryAndStatistics/index'),
        name: '数据查询',
        meta: { title: '数据查询', noCache: true }
      },
      {
        path: '/dataStatistics',
        component: () => import('@/views/DataQueryAndStatistics/dataStatistics.vue'),
        name: '数据统计',
        meta: { title: '数据统计', noCache: true }
      }
    ]
  },
  /*
    图像/视频存储模块。
    1、图像模块，图像上传。
    2、视频模块，视频上传与查询。
  */
  // {
  //   path: '/image',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   name: 'image',
  //   meta: {
  //     title: '图像存储',
  //     icon: 'el-icon-picture',
  //     roles: ['admin']
  //   },
  //   children: [
  //     {
  //       path: 'upload-image',
  //       component: () => import('@/views/Image/uploadImage'),
  //       name: 'uploadImage',
  //       meta: { title: '上传图像' }
  //     }
  //     // {
  //     //   path: 'export-image',
  //     //   component: () => import('@/views/Image/exportImage'),
  //     //   name: 'exportImage',
  //     //   meta: { title: '输出图像' }
  //     // }
  //   ]
  // },
  {
    path: '/video',
    component: Layout,
    redirect: 'noredirect',
    name: 'video',
    meta: {
      title: '视频存储',
      icon: 'el-icon-video-camera',
      roles: ['admin', 'editor']
    },
    children: [
      // {
      //   path: 'upload-video',
      //   component: () => import('@/views/Video/uploadVideo'),
      //   name: 'uploadVideo',
      //   meta: { title: '上传视频' }
      // },
      {
        path: 'export-video',
        component: () => import('@/views/Video/exportVideo'),
        name: 'exportVideo',
        meta: { title: '视频查询' }
      },
      {
        path: 'play-video',
        component: () => import('@/views/Video/playVideo'),
        name: 'playVideo',
        meta: { title: '视频播放' },
        hidden: true
      }
    ]
  },
  {
    path: '/systemMatching',
    component: Layout,
    redirect: 'noredirect',
    name: 'systemMatching',
    meta: {
      title: '系统配置',
      icon: 'el-icon-video-camera',
      roles: ['admin']
    },
    children: [
      // {
      //   path: 'system-matching',
      //   component: () => import('@/views/systemMatching/systemMatching'),
      //   name: 'systemMatching',
      //   meta: { title: '系统配置' }
      // },
      {
        path: 'system-matching-new',
        component: () => import('@/views/systemMatching/systemMatching_new'),
        name: 'systemMatching_new',
        meta: { title: '系统配置' }
      }
    ]
  },
  {
    path: '/pictureGeneration',
    component: Layout,
    redirect: 'noredirect',
    name: 'pictureGeneration',
    meta: {
      title: '合成图像',
      icon: 'el-icon-s-grid',
      roles: ['admin']
    },
    children: [
      {
        path: 'picture-generation',
        component: () => import('@/views/pictureGeneration/pictureGeneration'),
        name: 'pictureGeneration',
        meta: { title: '合成图像' }
      }
    ]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
